//
//  CELogController.swift
//  CJPack
//
//  Created by chenjingwei on 2025/4/29.
//

import UIKit
import SwiftUI

class CELogController: CJBaseBackController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupView()
    }
    
    func setupView() {
        var sv = CELogSView()
        sv.didLogAction = {
            kCJLog("打印")
            self.logAction()
        }
        sv.didLogLoopAction = {
            kCJLog("循环打印")
            self.logLoopAction()
        }
        
        let hc = UIHostingController(rootView: sv)
        cj_addHosting(hc: hc)
    }
    
    let text = "“时代不同，使命任务发生变化，但艰苦奋斗、团结奋斗、不懈奋斗的精神永远不会变。”4月28日，庆祝中华全国总工会成立100周年暨全国劳动模范和先进工作者表彰大会在北京人民大会堂隆重举行。习近平总书记出席大会并发表重要讲话时寄望我国工人阶级和广大劳动者，脚踏实地、奋发进取、拼搏奉献，用创造拥抱新时代，以奋斗铸就新辉煌，一步一个脚印把实现中华民族伟大复兴的宏伟蓝图变成现实！"
    
    func logAction() {
        CJPrint.log(text)
    }
    
    func logLoopAction() {
        DispatchQueue.global().async {
            for index in 1...10000 {
                CJPrint.log("\(index)" + self.text)
            }
        }
    }
}


struct CELogSView: View {
    
    var didLogAction: (() -> ()) = {}
    var didLogLoopAction: (() -> ()) = {}
    
    var body: some View {
        VStack {
            Button {
                didLogAction()
            } label: {
                Text("打印")
            }
            Spacer().frame(height: 10)
            Button {
                didLogLoopAction()
            } label: {
                Text("循环打印")
            }
        }
    }
}

#Preview {
    CELogSView()
}
